#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;


int Find(int* a, size_t size, int x)
{
	int i = 0;
	for (i; i < size; i++)
	{
		if (a[i] == x)
		{
			return i;
		}
	}
	return -1;
}

int binSearch(int* a, size_t size, int x)
{
	size_t l = 0, r = size - 1, mid;

	while (l <= r)
	{
		mid =(r + l) / 2;
		if (a[mid] == x)
		{
			return mid;
		}
		else if(a[mid] < x)
		{
			l = mid + 1;
		}
		else
		{
			r = mid - 1;
		}
	}

	return -1;
}


void t1()
{
	int a[] = { 10,9,8,7,6,5,4,3,2,1,11,12,13,14,15,16 };

	size_t size = sizeof(a) / sizeof(a[0]);

	printf("%d\n", a[Find(a, size, 13)]);
	printf("%d\n", a[Find(a, size, 2)]);
	printf("%d\n", a[Find(a, size, 4)]);
	printf("%d\n", a[Find(a, size, 11)]);
	printf("%d\n", a[Find(a, size, 1)]);
}

void t2()
{
	int a[] = { 1,2,3,4,5,6,7,8,9,10 };
	size_t size = sizeof(a) / sizeof(a[0]);
	printf("%d\n", a[binSearch(a, size, 1)]);
	printf("%d\n", a[binSearch(a, size, 2)]);
	printf("%d\n", a[binSearch(a, size, 3)]);
	printf("%d\n", a[binSearch(a, size, 4)]);
	printf("%d\n", a[binSearch(a, size, 9)]);
	printf("%d\n", a[binSearch(a, size, 8)]);
	printf("%d\n", a[binSearch(a, size, 7)]);
}

void t3()
{
	int a[] = { 160, 165, 167, 170, 180, 181, 183 };
	size_t size = sizeof(a) / sizeof(a[0]);

	printf("%d\n", binSearch(a, size, 160));
	printf("%d\n", binSearch(a, size, 180));
	printf("%d\n", binSearch(a, size, 167));
	printf("%d\n", binSearch(a, size, 175));
	printf("%d\n", binSearch(a, size, 190));


}

int main()
{
	t3();

	return 0;
}